package com.panda.multiple.tenant3.config;

import com.baomidou.mybatisplus.extension.plugins.handler.TenantLineHandler;
import lombok.extern.slf4j.Slf4j;
import net.sf.jsqlparser.expression.Expression;
import net.sf.jsqlparser.expression.StringValue;

@Slf4j
public class MyTenantLineHandler implements TenantLineHandler {

    private static final ThreadLocal<String> TENANT_ID = new ThreadLocal<>();

    public static void setTenantId(String tenantId) {
        TENANT_ID.set(tenantId);
    }

    @Override
    public Expression getTenantId() {
        String tenantId = TENANT_ID.get();
        TENANT_ID.remove();
        log.info("tenantId = {}", tenantId);
        return new StringValue(tenantId);
    }
}
